package models.application;

import java.util.List;

import javax.persistence.*;

import models.*;
import models.pubobj.*;
import models.user.AniUser;

import play.data.validation.Constraints;
import play.db.ebean.Model;

@Entity
public class AniApiAppRel extends Model {

	@Id
	public Long id;
	
	@ManyToOne
	public AniApp clientApp;
	
	@ManyToOne
	public AniApi targetApi;
	
	@ManyToOne
	public AniObjectState state;
	
	
	public static Model.Finder<Long, AniApiAppRel> find = new Model.Finder(Long.class, AniApiAppRel.class);
	
	public static AniApiAppRel withClientAppIdTargetApiId(Long clientAppId, Long targetApiId){
		return find.where().eq("clientApp.id", clientAppId).eq("targetApi.id", targetApiId).findUnique();
	}
	
	public AniApp getClientApp(){
		return AniApp.find.byId(this.clientApp.id);
	}
	
	public AniApi getTargetApi(){
		return AniApi.find.byId(targetApi.id);
	}
	
	public static List<AniApiAppRel> findAll() {
        return find.all();
    }
}
